DEFINITION FOR LIBRARY MODULE KeyMap ;

FROM SYSTEM	IMPORT ADDRESS, SHORTSET, LONGSET, STRING ;
FROM InputEvent IMPORT InputEventPtr ;
IMPORT Exec ;

TYPE
  KeyMapPtr	= POINTER TO KeyMap	       ;
  KeyMapNodePtr = POINTER TO KeyMapNodePtr     ;
  KeyMapTypePtr = POINTER TO ARRAY OF SHORTSET ;
  BitArrayPtr	= POINTER TO ARRAY OF LONGSET  ;
  KeyMapInfoPtr = POINTER TO ARRAY OF RECORD
  		      CASE :BOOLEAN OF
  		      | TRUE  : string : ADDRESS ;
  		      | FALSE : chars  : ARRAY [0..3] OF CHAR ;
  		      END ;
  		    END ;

  KeyMap = RECORD
    km_LoKeyMapTypes : KeyMapTypePtr	;
    km_LoKeyMap      : KeyMapInfoPtr	;
    km_LoCapsable    : BitArrayPtr	;
    km_LoRepeatable  : BitArrayPtr	;
    km_HiKeyMapTypes : KeyMapTypePtr	;
    km_HiKeyMap      : KeyMapInfoPtr	;
    km_HiCapsable    : BitArrayPtr	;
    km_HiRepeatable  : BitArrayPtr	;
  END ;

  KeyMapNode = RECORD
    kn_Node   : Exec.Node ;	(* including name of keymap *)
    kn_KeyMap : KeyMap    ;
  END ;

(* the structure of keymap.resource *)

TYPE
  KeyMapResource = RECORD
    kr_Node : Exec.Node ;
    kr_List : Exec.List ; (* a list of KeyMapNodes *)
  END ;
  KeyMapResourcePtr = POINTER TO KeyMapResource ;

(* Key Map Types *)
CONST
  KCB_SHIFT   = 0 ; KCF_SHIFT   = {KCB_SHIFT}   ;
  KCB_ALT     = 1 ; KCF_ALT     = {KCB_ALT}     ;
  KCB_CONTROL = 2 ; KCF_CONTROL = {KCB_CONTROL} ;
  KCB_DOWNUP  = 3 ; KCF_DOWNUP  = {KCB_DOWNUP}  ;

  KCB_DEAD = 5 ;	  (* may be dead or modified by dead key: *)
  KCF_DEAD = {KCB_DEAD} ; (* use dead prefix bytes		  *)

  KCB_STRING = 6 ; KCF_STRING = {KCB_STRING} ;
  KCB_NOP    = 7 ; KCF_NOP    = {KCB_NOP}    ;

  KC_NOQUAL   = { } ;
  KC_VANILLA  = KCF_SHIFT+KCF_ALT+KCF_CONTROL ;

(* Dead Prefix Bytes *)
  DPB_MOD  =  0  ; DPF_MOD  = {DPB_MOD}  ;
  DPB_DEAD =  3  ; DPF_DEAD = {DPB_DEAD} ;

  DP_2DINDEXMASK = 00FH ; (* mask for index for 1st of two dead keys   *)
  DP_2DFACSHIFT	 = 4 ;	  (* shift for factor for 1st of two dead keys *)

VAR
  KeymapBase : ADDRESS ;

(*--- functions in V36 or higher (Release 2.0) ---*)
PROCEDURE SetKeyMapDefault( skeyMap : KeyMapPtr ) ;
PROCEDURE AskKeyMapDefault( ) : KeyMapPtr ;

PROCEDURE MapRawKey( event  : InputEventPtr ;
		     buffer : STRING ;
		     length : LONGINT ;
		     keyMap : KeyMapPtr ) : INTEGER ;

PROCEDURE MapANSI( string : STRING  ;
		   count  : LONGINT ;
		   buffer : STRING  ;
		   length : LONGINT ;
		   keyMap : KeyMapPtr ) : LONGINT ;

END KeyMap.
